home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swags_z.zip / SOUND.SWG / 0056_General Midi Code.pas < prev    next >
Pascal/Delphi Source File  |  1995-03-03  |  5KB  |  147 lines

  1. {
  2. Here is the PASCAL version of a portion of the Assembler code I used in my
  3. game to get General Midi sound.  I've compiled the program, and it works fine
  4. on my GM device, MEGA-EM a TSR for the Gravis Ultrasound.
  5.  
  6. No checking is performed, make sure you have the correct hardware, but
  7. it should run due to the timeout checking.
  8.  
  9. If you don't get sound, then it's probably because no instrument was
  10. defined.  Send a program change midi sequence.
  11.  
  12. Feel free to toss this in SWAG.  Sound code is always requested,
  13. and General Midi is so simple compared to everything else.
  14. }
  15. Program GMTest;
  16.  
  17. (*
  18. Take from Colin Buckley's cheezy shareware game Tubes, written in BP.
  19. The actual GM code is a converted assembler file, thus the obvious macro
  20. like sequences, register passing, and semi-colon comments.  Sorry for any
  21. typos/bugs introduced during the quick conversion.
  22.  
  23. This is completely public domain.  Which means no restrictions whatsoever.
  24.  
  25. {$DEFINE EducateTheMasses}
  26. To the uninformed, you can not say something is public domain, then paste a
  27. copyright on it and say it's required for you to be acknowledged or
  28. get a post card or something.  You give up all rights when you give something
  29. to the public domain.  What you want, is called freeware.
  30. {$ENDIF}
  31. *)
  32.  
  33. Const
  34.   GMPort        = $331;
  35.   Send          = $80;
  36.   Receive       = $40;
  37.  
  38. { AL:=Command; }
  39. Procedure WriteGMCommand; Assembler;
  40. ASM
  41.     MOV   DX,GMPort                   {;DX:=GMStatusPort;                 }
  42.     PUSH  AX                          {;Save AX                           }
  43.     XOR   AX,AX                       {;AH:=TimeOutValue;                 }
  44. @@WaitLoop:
  45.     { ;Prevent Infinite Loop with Timeout }
  46.     DEC   AH                          {; |If TimeOutCount=0 then          }
  47.     JZ    @@TimeOut                   {;/   TimeOut;                      }
  48.     {; Wait until GM is ready }
  49.     IN    AL,DX                       {; |If Not Ready then               }
  50.     AND   AL,Receive                  {; |  WaitLoop;                     }
  51.     JNZ   @@WaitLoop                  {;/                                 }
  52. @@TimeOut:
  53.     POP   AX                          {;Restore AX                        }
  54.  
  55.     OUT   DX,AL                       {;Send Data                         }
  56. End;
  57.  
  58. { ; AL:=Data }
  59. Procedure WriteGM; Assembler;
  60. ASM
  61.     MOV   DX,GMPort                   {;DX:=GMStatusPort;                 }
  62.     PUSH  AX                          {;Save AX                           }
  63.     XOR   AX,AX                       {;AH:=TimeOutValue;                 }
  64. @@WaitLoop:
  65.     { ; Prevent Infinite Loop with Timeout }
  66.     DEC   AH                          {; |If TimeOutCount=0 then          }
  67.     JZ    @@TimeOut                   {;/   TimeOut;                      }
  68.     { ; Wait until GM is ready }
  69.     IN    AL,DX                       {; |If Not Ready then               }
  70.     AND   AL,Receive                  {; |  WaitLoop;                     }
  71.     JNZ   @@WaitLoop                  {;/                                 }
  72. @@TimeOut:
  73.     POP   AX                          {;Restore AX                        }
  74.  
  75.     DEC   DX                          {;DX:=DataPort                     }
  76.     OUT   DX,AL                       {;Send Data                        }
  77. End;
  78.  
  79. { ;Returns Data }
  80. Function ReadGM:Byte; Assembler;
  81. ASM
  82.     MOV   DX,GMPort                   {;DX:=GMStatusPort;                 }
  83.     PUSH  AX                          {;Save AX                           }
  84.     XOR   AX,AX                       {;AH:=TimeOutValue;                 }
  85. @@WaitLoop:
  86.     { ; Prevent Infinite Loop with Timeout }
  87.     DEC   AH                          {; |If TimeOutCount=0 then          }
  88.     JZ    @@TimeOut                   {;/   TimeOut;                      }
  89.     { ; Wait until GM is ready }
  90.     IN    AL,DX                       {; |If Not Ready then               }
  91.     AND   AL,Send                     {; |  WaitLoop;                     }
  92.     JNZ   @@WaitLoop                  {;/                                 }
  93. @@TimeOut:
  94.     POP   AX                          {;Restore AX                        }
  95.  
  96.     DEC   DX                          {;DX:=DataPort                      }
  97.     IN    AL,DX                       {;Receive Data                      }
  98. End;
  99.  
  100. Procedure ResetGM; Assembler;
  101. ASM
  102.     { ;Reset GM }
  103.     MOV   DX,GMPort
  104.     MOV   AL,0FFh
  105.     OUT   DX,AL
  106.     {; Get ACK }
  107.     CALL  ReadGM
  108.     {; UART Mode }
  109.     MOV   AL,03Fh
  110.     CALL  WriteGMCommand
  111. End;
  112.  
  113. Procedure SetNoteOn(Channel,Note,Volume:Byte); Assembler;
  114. ASM
  115.     MOV   AL,[Channel]
  116.     ADD   AL,90h
  117.     Call  WriteGM
  118.     MOV   AL,[Note]
  119.     CALL  WriteGM
  120.     MOV   AL,[Volume]
  121.     CALL  WriteGM
  122. End;
  123.  
  124. Procedure SetNoteOff(Channel,Note,Volume:Byte); Assembler;
  125. ASM
  126.     MOV   AL,[Channel]
  127.     ADD   AL,80h
  128.     Call  WriteGM
  129.     MOV   AL,[Note]
  130.     CALL  WriteGM
  131.     MOV   AL,[Volume]
  132.     CALL  WriteGM
  133. End;
  134.  
  135. Begin
  136.   ResetGM;
  137.   SetNoteOn(0,64,127);
  138.   ASM
  139.     { ;Wait for Key }
  140.     XOR   AX,AX
  141.     INT   16h
  142.   End;
  143.   SetNoteOff(0,64,127);
  144.   ResetGM;
  145. End.
  146.  
  147.